package com.kevin.training.meal.dao.impl;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.kevin.training.meal.dao.UserDao;
import com.kevin.training.meal.domain.User;
import com.kevin.training.meal.persistence.UserMapper;

@Named
public class UserDaoImpl implements UserDao {

	@Inject
	private UserMapper userMapper;

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public User create(User user) {
		userMapper.create(user);
		return user;
	}

	@Override
	public User get(int id) {
		return userMapper.get(id);
	}

	@Override
	public List<User> getAllIdAndNames() {
		return userMapper.getAllIdAndNames();
	}

	@Override
	@Transactional
	public void delete(int id) {
		userMapper.delete(id);
	}

	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}
}
